package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @description:
 * @author: LuoXuhuan
 * @date: 2020/10/29-0:09
 * @Version: 1.0.0
 */
@Service
@Slf4j
public class PermissionServiceImpl implements PermissionService{

    @Autowired
    PermissionDao permissionDao;

    @Override
    @Transactional
    public void addPermission(Permission permission) {

        permissionDao.addPermission(permission);

    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Permission> page = permissionDao.findPage(queryPageBean.getQueryString());

        PageResult pageResult = new PageResult(page.getTotal(),page);

        return pageResult;
    }

    @Override
    public Permission findById(Integer id) {

        Permission permission = permissionDao.findById(id);

        return permission;
    }

    @Override
    @Transactional
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    @Override
    @Transactional
    public void delById(Integer id) {
        permissionDao.delById(id);
    }
}